import {Injectable} from '@angular/core';
import {ThemeableBrowser, ThemeableBrowserObject, ThemeableBrowserOptions} from "@ionic-native/themeable-browser";
import {Platform} from "ionic-angular";

@Injectable()
export class ThemeBrowserService {

    browser: ThemeableBrowserObject;

    constructor(private themeableBrowser: ThemeableBrowser,
                private platform: Platform,) {
    }

    openBrowser(url: string,
        option?: { name?: string, id?: string|number, status?: boolean, callback1?: Function, callback2?: Function },
                shareOpt?: {shareWaySelectedEvent:string,buttons:Array<{wwwImage:string,}>,shareCallback?:Function}) {
        let toolbarHeight = 17.6;
        if (this.platform.is('android')) {
            toolbarHeight = 17.6
        } else {
            toolbarHeight = 10.6
        }

        const options: ThemeableBrowserOptions = {
            // statusbar: {//状态栏只支持纯色
            //     color: '#387EF5'
            // },
            toolbar: {
                height: toolbarHeight,
                image: 'menu_background'
            },
            backButtonCanClose: true,
            title: {//标题栏支持图片和颜色
                color: '#ffffff',
                showPageTitle: true,
                // staticText:'文字文字文字文字文字文字文字文字文字文字文字'
            },
            closeButton: {
                wwwImage: 'assets/images/common/icon_close.png',
                wwwImagePressed: 'assets/images/common/icon_close.png',
                wwwImageDensity: 2,
                align: 'left',
                event: 'closePressed'
            },
            backButton: {
                wwwImage: 'assets/images/common/icon_back.png',
                wwwImagePressed: 'assets/images/common/icon_back.png',
                wwwImageDensity: 2,
                align: 'left',
                event: 'backPressed'
            }
        };


        this.browser = this.themeableBrowser.create(url, '_blank', options);

    }

    setStatus(status: boolean) {
        console.log(status,'105');
        // this.browser.setCollectStatus(status).then(value => {
        //     console.log(value);
        // }, reason => {
        //     console.log(reason);
        // })
    }

}
